package edu.uoc.tdp.pac4.i18n;

import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

public class TDSLanguageUtils {
    private static ResourceBundle resourceBundle;
    private static String currentBaseName;
    private static Locale currentLocale;

    public static synchronized boolean setDefaultLanguage(String paramString) {
        try {
            currentBaseName = paramString;
            resourceBundle = ResourceBundle.getBundle(paramString, Locale.getDefault());
            return true;
        } catch (MissingResourceException localMissingResourceException) {
            localMissingResourceException.printStackTrace();
        }
        return false;
    }

    public static synchronized boolean setLanguage(String paramString, Locale paramLocale) {
        try {
            currentBaseName = paramString;
            currentLocale = paramLocale;
            resourceBundle = ResourceBundle.getBundle(paramString, paramLocale);
            return true;
        } catch (MissingResourceException localMissingResourceException) {
            localMissingResourceException.printStackTrace();
        }
        return false;
    }

    public static String getMessage(String paramString) {
        try {
            return resourceBundle.getString(paramString); 
        } catch (MissingResourceException localMissingResourceException) {
        }
        return new String();
    }

    public static String getCurrentBaseName() {
        return currentBaseName;
    }

    public static Locale getCurrentLocale() {
        return currentLocale;
    }
}